-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added ignore module pattern to calculate the first semester, solves #95 #97
base: master
Are you sure you want to change the base?
Conversation
Tried out the changes and works for me in chrome 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi and thanks for your contribution!
We can't test this ourselves since both me and @Lextum no longer have access to the MyCampus website, therefore we hope you have tested this well 😉
/** | ||
* list of modules that should be ignored to calculate the first semester | ||
* check if moduleName matches ignore pattern | ||
*/ | ||
shouldModuleBeIgnored: (hsluModuleName) => { | ||
const ignoreModulePatterns = ['INFO_ABEND']; | ||
let dontIgnore = true; | ||
ignoreModulePatterns.forEach(ignorePattern => { | ||
if(hsluModuleName.includes(ignorePattern)) { | ||
console.log(`ignoring module ${hsluModuleName} for first semester calculation`) | ||
dontIgnore = false; | ||
} | ||
}) | ||
|
||
return dontIgnore; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bool variables should always have a positive name, e.g. isTrue
rather than isNotTrue
. Otherwise the valid state is represented as a double negation as in this case with dontIgnore = false
meaning the module is invalid. This is simply very confusing.
Besides that, the method name doesn't correspond to what is actually returned. With a name like shouldModuleBeIgnored
, I'd expect the method to return true
if it is ignored and otherwise false
. But it does exactly the opposite.
I'd suggest to change the method like so to make it more easy to understand:
/** | |
* list of modules that should be ignored to calculate the first semester | |
* check if moduleName matches ignore pattern | |
*/ | |
shouldModuleBeIgnored: (hsluModuleName) => { | |
const ignoreModulePatterns = ['INFO_ABEND']; | |
let dontIgnore = true; | |
ignoreModulePatterns.forEach(ignorePattern => { | |
if(hsluModuleName.includes(ignorePattern)) { | |
console.log(`ignoring module ${hsluModuleName} for first semester calculation`) | |
dontIgnore = false; | |
} | |
}) | |
return dontIgnore; | |
}, | |
/** | |
* Check if a module should be included in the first semester calculation. | |
*/ | |
isModuleValid: (hsluModuleName) => { | |
const ignoreModulePatterns = ['INFO_ABEND']; | |
let isValid = true; | |
ignoreModulePatterns.forEach(ignorePattern => { | |
if (moduleName.includes(ignorePattern)) { | |
console.log(`ignoring module ${hsluModuleName} for first semester calculation`) | |
isValid = false; | |
} | |
}) | |
return isValid; | |
}, |
@@ -157,6 +173,8 @@ const ModuleParser = { | |||
firstModule = anlasslistApiResponse.items | |||
.slice() | |||
.reverse() | |||
//check if module is is in the ignore list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add a comment if the method name and docs already explain what's going on :)
let dontIgnore = true; | ||
ignoreModulePatterns.forEach(ignorePattern => { | ||
if(hsluModuleName.includes(ignorePattern)) { | ||
console.log(`ignoring module ${hsluModuleName} for first semester calculation`) | ||
dontIgnore = false; | ||
} | ||
}) | ||
|
||
return dontIgnore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let dontIgnore = true; | |
ignoreModulePatterns.forEach(ignorePattern => { | |
if(hsluModuleName.includes(ignorePattern)) { | |
console.log(`ignoring module ${hsluModuleName} for first semester calculation`) | |
dontIgnore = false; | |
} | |
}) | |
return dontIgnore; | |
return ignoreModulePatterns.every(pattern => !hsluModuleName.includes(pattern)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this solution even better 👍
I added a new static list of module name patterns that should be ignored on the first semester calculation.
These are only ignored on the
firstModule
calculation.This solves the issue #95.
If you want another solution I'm open to it.
Maybe we should also ignore modules that are in
ignoreInStatsModules
.